home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Guess 100 (actually 64 hex)
- ;
- ; Computer picks a number and gives you 7 chances to guess it.
- ;
- ; RTK, 12-17-93
- ;
-
- #include std.equ
-
- #org 1000
-
- #equ random 205 ; use only the low byte
- #equ number 17 ; store the number to guess here
- #equ count 18 ; store the number of guesses remaining
-
- lda #07
- sta count ; setup count
- lda #0c
- jsr _cout ; clear the screen
- lda >greeting ; get the greeting
- ldx <greeting
- jsr _print
- jsr getNumber ; pick a random number
- .prompt lda >promptText
- ldx <promptText
- jsr _print
- jsr _input1 ; get a number
- lda >text
- ldx <text
- jsr _upper ; make it uppercase
- lda >text
- ldx <text
- jsr _number ; make it a number
- lda $02 ; get the guess (low part only)
- cmp number ; compare to the computer's number
- beq winner ; got it!
- blt tooLow ; too low
- .tooHigh lda >high ; print 'Too high!'
- ldx <high
- jsr _print
- jmp decrement ; reduce chances
- .tooLow lda >low ; print 'Too low!'
- ldx <low
- jsr _print
- .decrement dec count ; reduce count
- beq loser ; oh,oh, out of chances!
- jmp prompt
- .loser lda >lose ; game over, you lose
- ldx <lose
- jsr _print
- lda number
- jsr _printHex
- lda #0d
- jsr _cout
- jsr _cout
- jmp end
- .winner lda >win ; you win!
- ldx <win
- jsr _print
- .end rts ; end
-
- ; getNumber - picks a random number
-
- .getNumber lda random ; get a random number
- cmp #64 ; compare to 100
- bgt getNumber ; try again until < 100
- sta number ; and save it
- rts
-
- ; string data
-
- .greeting asc 'GUESS 100. The computer is thinking of a number between 0'
- asc ' and 100'
- hex 0d
- asc '(actually 64 since the game is in hexadecimal).'
- hex 0d0d
- asc 'You enter a number and the computer will tell you if it '
- hex 0d
- asc 'is too high, too low or correct. You have 7 tries.'
- hex 0d0d00
- .promptText asc 'Your guess ? '
- hex 00
- .high asc 'Too high!'
- hex 0d00
- .low asc 'Too low!'
- hex 0d00
- .lose asc 'Sorry, you lose! The number was '
- hex 00
- .win asc 'Correct! You win!'
- hex 0d0d00
-